/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package YottaTron.Actions;

import YottaTron.Sprites.Sprite;
import YottaTron.*;
import YottaTron.Sprites.PlayerSprite;
import org.lwjgl.util.Timer;

/**
 *
 * @author Cenda
 */
public class AccelerateAction extends Action {
float totalTime = 0;
    public AccelerateAction(Sprite s, float startingTime, Runner r) {
        sprite = s;
        this.startingTime = startingTime;
        this.r = r;
        iterations = 0;
        type = ACCELERATE_ACTION;
        //System.out.println(" zrychluji na "  + rychlost);
        finished = false;
        saveToHistory = true;

        PlayerSprite player = ((PlayerSprite) s);
        if (player.controllable) {
            player.addLastAction(this);
        }
    }

    public boolean nextStep(float deltaTime) {
        if (finished) {

            
            totalTime += deltaTime;
//            System.out.println("ukoncuji akceleraci " + deltaTime);
//            System.out.println("total Time = " + totalTime);
//            System.out.println("expected Total Time = " + (finishTime - startingTime));
            sprite.setSpeed(sprite.getSpeed() + sprite.getAcceleration() * deltaTime);
            sprite.variableChanged = true;
            return false;
        }
        
        if (sprite.getSpeed() < sprite.getMaxSpeed()) {
            if (iterations == 0) {
                 //                float deltaTime = currentTime - startingTime;
//                totalTime += deltaTime;
//                System.out.println("zacinam akcelerovat = " + deltaTime);
//                sprite.setSpeed(sprite.getSpeed() + sprite.getAcceleration() * deltaTime);

            } else {
                
                
//                System.out.println("akceleruji po dobu " + deltaTime);
//                System.out.println("akceleruji " +  deltaTime);
                sprite.setSpeed(sprite.getSpeed() + sprite.getAcceleration() * deltaTime);
                sprite.variableChanged = true;
            }
            iterations++;
        }
        totalTime += deltaTime;
        //System.out.println("akceleruji");
        return true;

    }

          
}

